#实现一个自动取款机的存取款模拟效果。
#要求有登陆和退出、查询余额、取钱，存钱等操作。 
#定义一个用于存放储户信息的变量   列表 用字典存
banklist = [
          {"Cardid":"夏薇","password":'111',"money":5000.0},
          {"Cardid":"夏夏夏","password":'222',"money":300.2},
          {"Cardid":"微微微","password":'333',"money":45.3},
          ]

#定义登录函数 
def denglu(banklist):

    '''
     判断输入的用户名和密码与字典里存的是否相同
    '''
    for i in range(len(banklist)):
    	if banklist[i]['Cardid']==a and banklist[i]['password']==b:
    	    print("账号密码正确登陆成功！欢迎",a)
    	    print("="*55) 
    	    return 2
    	
    print("账号/密码错误请核实！") 

#定义一个查询余额函数 

def selectYue(banklist):
    '''
    用于查询已知用户名条件下余额是多少
    '''
    for i in range(len(banklist)):
    	if banklist[i]['Cardid']==a:
    	    return  banklist[i]['money']
    
#定义一个存钱函数 

def selectCun(banklist,addmoney):

    '''
    给登录的用户存钱
    '''
    for i in range(len(banklist)):

    	if banklist[i]['Cardid']==a:

            banklist[i]['money'] = banklist[i]['money']+float(addmoney)
            return  banklist[i]['money']
    
#定义一个取钱函数 
def selectQu(banklist,de):
    '''
    给登录的用户取钱
    '''
    for i in range(len(banklist)):
    	if banklist[i]['Cardid']==a:
            banklist[i]['money'] = banklist[i]['money']-float(de)   
            return  banklist[i]['money']
    

#第一步是登录操作   只有登录成功才有后续操作
print("="*20,"银行ATM机登录","="*20)
print("请输入账号密码登录（只有登录成功才可以进行后续查询存取操作）")
a= input("您的账号：")
b= input("您的密码：")
if denglu(banklist) ==2:
	#输出的初始界面
    while True:
            print("="*20,"银行ATM机操作","="*20)
            print("{0:5}{1:10}{2:10}".format("","1.退出当前账户","2.查询账户余额"))
            print("{0:5}{1:14}{2:10}".format("","3.存钱","4.取钱"))
            print("="*55)
            key= input("请输入对应的选择：")
            if key == '1':
                print ('='*20,'再见！','='*20)
                break
            elif key == '2':
               
                print (a,'您的账户余额为：', selectYue(banklist))
                
            elif key == '3':
                print (a,'您的账户余额为：', selectYue(banklist))
                addmoney= input("请输入存入金额：")
                print (a,'您的账户存入', addmoney,'现在余额为',selectCun(banklist,addmoney))
                print ('='*55)
            
            elif key == '4':
                
                print (a,'您的账户余额为：', selectYue(banklist))
                de= input("请输入取出金额：")
                print (a,'您的账户取出', de,'现在余额为',selectQu(banklist,de))
                print ('='*55)
               
            else:
                  print ('您输入的数值有误')

